<template>
  <div>
    <el-dialog
      title="详情"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
      class="dialog"
    >
      <div>
        <span>维修单号:</span><span>{{ form.id }}</span>
      </div>
      <div>
        <span>用户:</span><span>{{ form.username }}</span>
      </div>
      <div>
        <span>维修原因:</span><span>{{ form.reason }}</span>
      </div>
      <div>
        <span>品牌:</span><span>{{ form.brand }}</span>
      </div>
      <div>
        <span>商品名称:</span><span>{{ form.shopnames }}</span>
      </div>
      <div v-if="form.status == 2">
        <span>维修处理说明:</span
        ><el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="form.textarea"
          style="margin: 1% 0 0"
        >
        </el-input>
      </div>
      <div>
        <el-button
          type="success"
          size="small"
          v-if="form.status == 1"
          @click="controls(2, form.id)"
          >签收货物</el-button
        >
        <el-button
          type="success"
          size="small"
          v-if="form.status == 2"
          @click="controls(3, form.id)"
          >已发出</el-button
        >
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span> -->
    </el-dialog>
  </div>
</template>

<script>
import { bossBtns } from "@/api/shop";
import { postAnswer } from "@/api/login";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        status: "", //状态
        id: "",
        username: "",
        reason: "",
        brand: "",
        shopnames: "",
        textarea: "", //维修原因
      },
    };
  },
  /* 过滤器 */
  filters: {
    filterStatus(e) {
      switch (e) {
        case "0":
          return "已下单";
        case "2":
          return "已取消";
      }
    },
  },
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    controls(e, k) {
      let obj = {
        id: this.form.id,
        status: e,
      };
      if (e == 2) {
        bossBtns(obj).then((res) => {
          if (res.code == 200) {
            this.$message.success("操作成功!");
            this.dialogVisible = false;
            this.$parent.getData();
          }
        });
      } else if (e == 3) {
        if (this.form.textarea != "") {
          bossBtns(obj).then((res) => {
            if (res.code == 200) {
              postAnswer({
                id: this.form.id,
                reports: this.form.textarea,
              }).then((res) => {
                if (res.code == 200) {
                  this.$message.success("操作成功!");
                }
              });
              this.dialogVisible = false;
              this.$parent.getData();
            }
          });
        } else {
          this.$message.warning("请填写维修说明");
        }
      }
    },
    returnMoney(e) {
      console.log(e, "eell");
      // returnMoney()
      let obj = {
        username: this.form.username,
        total: this.form.total,
      };
      returnMoney(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("退款成功");
          this.$nextTick(() => {
            this.controls(4, this.form.id);
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-dialog__body > div {
  margin-bottom: 1vw;
}
.dialog span {
}
</style>
